package utils;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;


public class Configuraciones {

	private File f;
	private Properties prop;
	private InputStream is;
	
	public Configuraciones(String filePath) throws IOException{
		
		f = new File(filePath);
		
		if(!f.exists()){
			try {
				f.createNewFile();
			} catch (IOException e) {
				e.printStackTrace();
				throw e;
			}
		}
		
		prop = new Properties();
		is = null;

		try {
		  is=new FileInputStream(filePath);
		  prop.load(is);
		} catch(IOException ioe) {
			ioe.printStackTrace();
			throw new IOException("Error a la hora de abrir el archivo...");
		}
	}
	
	public String getProperty(String key){
		String p = prop.getProperty(key);
		return p;
	}
	
	public void setProperty(String key, String value, String comment){
		FileOutputStream out = null;
		prop.setProperty(key, value);
		try { 
            out = new FileOutputStream(f); 
            prop.store(out, comment);
        } catch (IOException e) { 
            e.printStackTrace(); 
        } 
	}
	
	public void setProperty(String key, String value){
		FileOutputStream out = null;
		prop.setProperty(key, value);
		try { 
            out = new FileOutputStream(f); 
            prop.store(out, "Configuraciones");
        } catch (IOException e) { 
            e.printStackTrace(); 
        } 
	}

}